
clear all 

//define folder global here

gl Inputs "$folder\1_Inputs"
gl Intermediate "$folder\2_Intermediate"
gl Outputs "$folder\3_Outputs"

********************************************************************************
********************************************************************************
**# TABLE I.3

import delimited "${Inputs}\NY_moves_by_source.tex", clear

	drop if !regexm(v1, "&")
	replace v1 = subinstr(v1, "\multicolumn{1}{c}{\parbox{0.6in}", "", .)
	replace v1 = subinstr(v1, "\centering \footnotesize", "", .)
	replace v1 = subinstr(v1, "\phantom{space}", "", .)
	replace v1 = subinstr(v1, "{", "", .)
	replace v1 = subinstr(v1, "}", "", .)
	replace v1 = subinstr(v1, "\sym", "", .)
	replace v1 = subinstr(v1, "\\ \hline", "", .)
	replace v1 = subinstr(v1, "\\", "", .)
	
	split v1, parse("&")
	drop v1 
	rename v1* var*
	replace var1 = trim(var1)
	replace var2 = trim(var2)
	replace var3 = trim(var3)
	replace var4 = trim(var4)
	replace var5 = trim(var5)
	replace var6 = trim(var6)
	
	gen 	type = "label" in 1
	replace type = "colnum" in 2
	replace type = "co" in 3
	replace type = "se" in 4
	replace type = "obs" in 5
	
	reshape long var, i(type) j(col) string 
	drop if type=="colnum" | col=="1" | type=="col"
	replace col = "v_" + col
	isid col type

levelsof col, local(cols)
levelsof type, local(typs)

foreach cox in `cols' {
	local id1 = "`cox'"
	
	foreach tyx in `typs' {
		local id2 = "`tyx'"
		
		levelsof var if col=="`cox'" & type=="`tyx'", clean local(`id1'_`id2')
		di "`id1'_`id2'"
	}
}

gl x " "	
		
texdoc init "${Outputs}/Supplementary data_Table_I3.tex", replace force 
tex {\footnotesize \begin{tabular}{l c c c c c} \hline \toprule ///
	& Move  	& Move 			& Move 			& Only Benefits & Only Infutor	\\
tex & in Either & in Benefits 	& in Infutor 	& Available 	& Available	 	\\

tex & (1) & (2) & (3) & (4) & (5) \\
tex \cmidrule{2-6}

tex $x Evicted	& `v_2_co' & `v_3_co' & `v_4_co' & `v_5_co' & `v_6_co' \\
tex $x 					& `v_2_se' & `v_3_se' & `v_4_se' & `v_5_se' & `v_6_se' \\

tex \midrule 
tex $x Observations		& `v_2_obs' & `v_3_obs' & `v_4_obs' & `v_5_obs' & `v_6_obs' \\

tex \bottomrule \\
tex	\end{tabular} }
texdoc close
	
	
	
********************************************************************************
********************************************************************************
**# TABLE I.4

use "${Inputs}\NY_attrition.dta", clear

	gen 	name = "pearn" 	if outcome=="Any Post Earnings"
	replace name = "pearn4" if outcome=="Any Post Earnings Q4+"
	replace name = "pearn8" if outcome=="Any Post Earnings Q8+"
	replace name = "pben" 	if outcome=="Any Post Benefits"
	replace name = "phosp" 	if outcome=="Any Post Hospitalization"
	replace name = "prec" 	if outcome=="Any Post Record"
	
	gen 	cont = "yes" 	if controls=="with Controls"
	replace cont = "no" 	if controls=="No Controls"
	
	gen zscore = beta / se
	gen pvalue = 2 * (1-normal(abs(zscore)))
	
	gen 	stars = "***" if pvalue < 0.01
	replace stars = "**" if pvalue < 0.05 & mi(stars)
	replace stars = "*" if pvalue < 0.1 & mi(stars)
	
	gen		numco = string(beta, "%10.4fc") + stars
	gen 	numse = "(" + string(se, "%10.4fc") + ")"
	gen 	numobs = string(N, "%10.0fc")
	
	drop beta se N zscore pvalue stars outcome controls
	reshape long num, i(name cont) j(type) string
	
	isid name cont typ
	compress
	
levelsof name, local(nams)
levelsof type, local(typs)
levelsof cont, local(cons)
	
foreach nax in `nams' {
	local id1 = "`nax'"
	
	foreach tyx in `typs' {
		local id2 = "`tyx'"
		
		foreach cox in `cons' {
			local id3 = "`cox'"
		
		levelsof num if name=="`nax'" & ///
						type=="`tyx'" & ///
						cont=="`cox'" , clean local(`id1'_`id2'_`id3')
		di "`id1'_`id2'_`id3'"
	}
}
}

texdoc init "${Outputs}/Supplementary data_Table_I4.tex", replace force 
tex {\footnotesize \begin{tabular}{l c c c c c c c c c c c c c c c c c} \hline \toprule ///
	& \multicolumn{2}{c}{Any Post} & & \multicolumn{2}{c}{Any Post} & & \multicolumn{2}{c}{Any Post} & ///
	& \multicolumn{2}{c}{Any Post} & & \multicolumn{2}{c}{Any Post} & & \multicolumn{2}{c}{Any Post} \\

tex	& \multicolumn{2}{c}{Earnings} & & \multicolumn{2}{c}{Earnings Q4+} & & \multicolumn{2}{c}{Earnings Q8+} & ///
	& \multicolumn{2}{c}{Benefits} & & \multicolumn{2}{c}{Hospitalization} & & \multicolumn{2}{c}{Record} \\
	
tex & (1) & (2) & & (3) & (4) & & (5) & (6) & & (7) & (8) & & (9) & (10) & & (11) & (12) \\
tex \cmidrule{2-3} \cmidrule{5-6} \cmidrule{8-9} \cmidrule{11-12} \cmidrule{14-15} \cmidrule{17-18}

tex $x Judge stringency 		& `pearn_co_no' & `pearn_co_yes' 	& & `pearn4_co_no' 	& `pearn4_co_yes' 	& & `pearn8_co_no' 	& `pearn8_co_yes' & ///
						& `pben_co_no' 	& `pben_co_yes' 	& & `phosp_co_no' 	& `phosp_co_yes' 	& & `prec_co_no' 	& `prec_co_yes'  \\
						
tex 					& `pearn_se_no' & `pearn_se_yes' 	& & `pearn4_se_no' 	& `pearn4_se_yes' 	& & `pearn8_se_no' 	& `pearn8_se_yes' & ///
						& `pben_se_no' 	& `pben_se_yes' 	& & `phosp_se_no' 	& `phosp_se_yes' 	& & `prec_se_no' 	& `prec_se_yes'  \\


tex $x Controls 		& No & Yes & & No & Yes & & No & Yes & & No & Yes & & No & Yes & & No & Yes  \\ 						
tex \midrule
tex $x Observations 	& `pearn_obs_no' & `pearn_obs_yes' 	& & `pearn4_obs_no' & `pearn4_obs_yes' 	& & `pearn8_obs_no' & `pearn8_obs_yes' & ///
						& `pben_obs_no' & `pben_obs_yes' 	& & `phosp_obs_no' 	& `phosp_obs_yes' 	& & `prec_obs_no' 	& `prec_obs_yes'  \\

tex \bottomrule \\
tex	\end{tabular} }
texdoc close

	